package com.huawei.appmarket.framework.widget.uxwidget.roundedimageview;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.ColorFilter;
import android.graphics.Shader.TileMode;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.net.Uri;
import android.util.AttributeSet;
import android.widget.ImageView;

import androidx.annotation.ColorInt;
import androidx.annotation.DimenRes;
import androidx.annotation.DrawableRes;
import o.dkw;
import o.dky.o;
import o.Logger;

public class RoundedImageView extends ImageView {
    static final /* synthetic */ boolean ˊ;
    private static final ScaleType[] ˋ = new ScaleType[]{ScaleType.MATRIX, ScaleType.FIT_XY, ScaleType.FIT_START, ScaleType.FIT_CENTER, ScaleType.FIT_END, ScaleType.CENTER, ScaleType.CENTER_CROP, ScaleType.CENTER_INSIDE};
    public static final TileMode ॱ = TileMode.CLAMP;
    private Drawable ʻ;
    private ScaleType ʻॱ;
    private ColorStateList ʼ;
    private float ʽ;
    private int ˊॱ;
    private boolean ˋॱ;
    private Drawable ˎ;
    private final float[] ˏ;
    private boolean ˏॱ;
    private int ͺ;
    private boolean ॱˊ;
    private TileMode ॱˋ;
    private boolean ॱॱ;
    private TileMode ॱᐝ;
    private ColorFilter ᐝ;

    static /* synthetic */ class AnonymousClass3 {
        static final /* synthetic */ int[] ॱ = new int[ScaleType.values().length];

        static {
            try {
                ॱ[ScaleType.CENTER.ordinal()] = 1;
            } catch (NoSuchFieldError e) {
            }
            try {
                ॱ[ScaleType.CENTER_CROP.ordinal()] = 2;
            } catch (NoSuchFieldError e2) {
            }
            try {
                ॱ[ScaleType.CENTER_INSIDE.ordinal()] = 3;
            } catch (NoSuchFieldError e3) {
            }
            try {
                ॱ[ScaleType.FIT_CENTER.ordinal()] = 4;
            } catch (NoSuchFieldError e4) {
            }
            try {
                ॱ[ScaleType.FIT_START.ordinal()] = 5;
            } catch (NoSuchFieldError e5) {
            }
            try {
                ॱ[ScaleType.FIT_END.ordinal()] = 6;
            } catch (NoSuchFieldError e6) {
            }
            try {
                ॱ[ScaleType.FIT_XY.ordinal()] = 7;
            } catch (NoSuchFieldError e7) {
            }
        }
    }

    static {
        boolean z;
        if (RoundedImageView.class.desiredAssertionStatus()) {
            z = false;
        } else {
            z = true;
        }
        ˊ = z;
    }

    public RoundedImageView(Context context) {
        super(context);
        this.ˏ = new float[]{0.0f, 0.0f, 0.0f, 0.0f};
        this.ʼ = ColorStateList.valueOf(-16777216);
        this.ʽ = 0.0f;
        this.ᐝ = null;
        this.ॱॱ = false;
        this.ˋॱ = false;
        this.ॱˊ = false;
        this.ˏॱ = false;
        this.ॱˋ = ॱ;
        this.ॱᐝ = ॱ;
    }

    public RoundedImageView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public RoundedImageView(Context context, AttributeSet attributeSet, int i) {
        int i2;
        super(context, attributeSet, i);
        this.ˏ = new float[]{0.0f, 0.0f, 0.0f, 0.0f};
        this.ʼ = ColorStateList.valueOf(-16777216);
        this.ʽ = 0.0f;
        this.ᐝ = null;
        this.ॱॱ = false;
        this.ˋॱ = false;
        this.ॱˊ = false;
        this.ˏॱ = false;
        this.ॱˋ = ॱ;
        this.ॱᐝ = ॱ;
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, o.ॱˉ, i, 0);
        int i3 = obtainStyledAttributes.getInt(o.ॱـ, -1);
        if (i3 >= 0) {
            setScaleType(ˋ[i3]);
        } else {
            setScaleType(ScaleType.FIT_CENTER);
        }
        float dimensionPixelSize = (float) obtainStyledAttributes.getDimensionPixelSize(o.ॱᐨ, -1);
        this.ˏ[0] = (float) obtainStyledAttributes.getDimensionPixelSize(o.ॱㆍ, -1);
        this.ˏ[1] = (float) obtainStyledAttributes.getDimensionPixelSize(o.ॱᶥ, -1);
        this.ˏ[2] = (float) obtainStyledAttributes.getDimensionPixelSize(o.ॱᐧ, -1);
        this.ˏ[3] = (float) obtainStyledAttributes.getDimensionPixelSize(o.ॱꓸ, -1);
        int length = this.ˏ.length;
        boolean z = false;
        for (i2 = 0; i2 < length; i2++) {
            if (this.ˏ[i2] < 0.0f) {
                this.ˏ[i2] = 0.0f;
            } else {
                z = true;
            }
        }
        if (!z) {
            float f;
            if (dimensionPixelSize < 0.0f) {
                f = 0.0f;
            } else {
                f = dimensionPixelSize;
            }
            i2 = this.ˏ.length;
            for (int i4 = 0; i4 < i2; i4++) {
                this.ˏ[i4] = f;
            }
        }
        this.ʽ = (float) obtainStyledAttributes.getDimensionPixelSize(o.ॱꜞ, -1);
        if (this.ʽ < 0.0f) {
            this.ʽ = 0.0f;
        }
        this.ʼ = obtainStyledAttributes.getColorStateList(o.ॱﾞ);
        if (this.ʼ == null) {
            this.ʼ = ColorStateList.valueOf(-16777216);
        }
        this.ˏॱ = obtainStyledAttributes.getBoolean(o.ॱꜟ, false);
        this.ॱˊ = obtainStyledAttributes.getBoolean(o.ॱꞌ, false);
        i3 = obtainStyledAttributes.getInt(o.ॱﹳ, -2);
        if (i3 != -2) {
            setTileModeX(ˋ(i3));
            setTileModeY(ˋ(i3));
        }
        i3 = obtainStyledAttributes.getInt(o.ॱﾟ, -2);
        if (i3 != -2) {
            setTileModeX(ˋ(i3));
        }
        i3 = obtainStyledAttributes.getInt(o.ᐧॱ, -2);
        if (i3 != -2) {
            setTileModeY(ˋ(i3));
        }
        ˏ();
        ˏ(true);
        if (this.ˏॱ) {
            super.setBackgroundDrawable(this.ˎ);
        }
        obtainStyledAttributes.recycle();
    }

    private static TileMode ˋ(int i) {
        switch (i) {
            case 0:
                return TileMode.CLAMP;
            case 1:
                return TileMode.REPEAT;
            case 2:
                return TileMode.MIRROR;
            default:
                return null;
        }
    }

    protected void drawableStateChanged() {
        super.drawableStateChanged();
        invalidate();
    }

    public ScaleType getScaleType() {
        return this.ʻॱ;
    }

    public void setScaleType(ScaleType scaleType) {
        if (!ˊ && scaleType == null) {
            throw new AssertionError();
        } else if (this.ʻॱ != scaleType) {
            this.ʻॱ = scaleType;
            switch (AnonymousClass3.ॱ[scaleType.ordinal()]) {
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                case 7:
                    super.setScaleType(ScaleType.FIT_XY);
                    break;
                default:
                    super.setScaleType(scaleType);
                    break;
            }
            ˏ();
            ˏ(false);
            invalidate();
        }
    }

    public void setImageDrawable(Drawable drawable) {
        this.ͺ = 0;
        this.ʻ = dkw.ˎ(drawable);
        ˏ();
        super.setImageDrawable(this.ʻ);
    }

    public void setImageBitmap(Bitmap bitmap) {
        this.ͺ = 0;
        this.ʻ = dkw.ˎ(bitmap);
        ˏ();
        super.setImageDrawable(this.ʻ);
    }

    public void setImageResource(@DrawableRes int i) {
        if (this.ͺ != i) {
            this.ͺ = i;
            this.ʻ = ˋ();
            ˏ();
            super.setImageDrawable(this.ʻ);
        }
    }

    public void setImageURI(Uri uri) {
        super.setImageURI(uri);
        setImageDrawable(getDrawable());
    }

    private Drawable ˋ() {
        Drawable drawable = null;
        Resources resources = getResources();
        if (resources == null) {
            return drawable;
        }
        if (this.ͺ != 0) {
            try {
                drawable = resources.getDrawable(this.ͺ);
            } catch (Exception e) {
                Logger.ˋ("RoundedImageView", "Unable to find resource: " + this.ͺ + e.toString());
                this.ͺ = 0;
            }
        }
        return dkw.ˎ(drawable);
    }

    public void setBackground(Drawable drawable) {
        setBackgroundDrawable(drawable);
    }

    public void setBackgroundResource(@DrawableRes int i) {
        if (this.ˊॱ != i) {
            this.ˊॱ = i;
            this.ˎ = ˊ();
            setBackgroundDrawable(this.ˎ);
        }
    }

    public void setBackgroundColor(int i) {
        this.ˎ = new ColorDrawable(i);
        setBackgroundDrawable(this.ˎ);
    }

    private Drawable ˊ() {
        Drawable drawable = null;
        Resources resources = getResources();
        if (resources == null) {
            return drawable;
        }
        if (this.ˊॱ != 0) {
            try {
                drawable = resources.getDrawable(this.ˊॱ);
            } catch (Exception e) {
                Logger.ˋ("RoundedImageView", "Unable to find resource: " + this.ˊॱ + e.toString());
                this.ˊॱ = 0;
            }
        }
        return dkw.ˎ(drawable);
    }

    private void ˏ() {
        ˎ(this.ʻ, this.ʻॱ);
    }

    private void ˏ(boolean z) {
        if (this.ˏॱ) {
            if (z) {
                this.ˎ = dkw.ˎ(this.ˎ);
            }
            ˎ(this.ˎ, ScaleType.FIT_XY);
        }
    }

    public void setColorFilter(ColorFilter colorFilter) {
        if (this.ᐝ != colorFilter) {
            this.ᐝ = colorFilter;
            this.ˋॱ = true;
            this.ॱॱ = true;
            ॱ();
            invalidate();
        }
    }

    private void ॱ() {
        if (this.ʻ != null && this.ॱॱ) {
            this.ʻ = this.ʻ.mutate();
            if (this.ˋॱ) {
                this.ʻ.setColorFilter(this.ᐝ);
            }
        }
    }

    private void ˎ(Drawable drawable, ScaleType scaleType) {
        if (drawable != null) {
            if (drawable instanceof dkw) {
                ((dkw) drawable).ˏ(scaleType).ˋ(this.ʽ).ˊ(this.ʼ).ˏ(this.ॱˊ).ˋ(this.ॱˋ).ˏ(this.ॱᐝ);
                if (this.ˏ != null) {
                    ((dkw) drawable).ˏ(this.ˏ[0], this.ˏ[1], this.ˏ[2], this.ˏ[3]);
                }
                ॱ();
            } else if (drawable instanceof LayerDrawable) {
                LayerDrawable layerDrawable = (LayerDrawable) drawable;
                int numberOfLayers = layerDrawable.getNumberOfLayers();
                for (int i = 0; i < numberOfLayers; i++) {
                    ˎ(layerDrawable.getDrawable(i), scaleType);
                }
            }
        }
    }

    public void setBackgroundDrawable(Drawable drawable) {
        this.ˎ = drawable;
        ˏ(true);
        super.setBackgroundDrawable(this.ˎ);
    }

    public void setCornerRadius(float f) {
        setCornerRadius(f, f, f, f);
    }

    public void setCornerRadiusDimen(@DimenRes int i) {
        float dimension = getResources().getDimension(i);
        setCornerRadius(dimension, dimension, dimension, dimension);
    }

    public void setCornerRadiusDimen(int i, @DimenRes int i2) {
        setCornerRadius(i, (float) getResources().getDimensionPixelSize(i2));
    }

    public void setCornerRadius(int i, float f) {
        if (Math.abs(this.ˏ[i] - f) >= 1.0E-7f) {
            this.ˏ[i] = f;
            ˏ();
            ˏ(false);
            invalidate();
        }
    }

    public void setCornerRadius(float f, float f2, float f3, float f4) {
        if (Math.abs(this.ˏ[0] - f) >= 1.0E-7f || this.ˏ[1] - f2 >= 1.0E-7f || this.ˏ[2] - f4 >= 1.0E-7f || this.ˏ[3] - f3 >= 1.0E-7f) {
            this.ˏ[0] = f;
            this.ˏ[1] = f2;
            this.ˏ[3] = f3;
            this.ˏ[2] = f4;
            ˏ();
            ˏ(false);
            invalidate();
        }
    }

    public void setBorderWidth(float f) {
        if (Math.abs(this.ʽ - f) >= 1.0E-7f) {
            this.ʽ = f;
            ˏ();
            ˏ(false);
            invalidate();
        }
    }

    public void setBorderWidth(@DimenRes int i) {
        setBorderWidth(getResources().getDimension(i));
    }

    public void setBorderColor(ColorStateList colorStateList) {
        if (!this.ʼ.equals(colorStateList)) {
            if (colorStateList == null) {
                colorStateList = ColorStateList.valueOf(-16777216);
            }
            this.ʼ = colorStateList;
            ˏ();
            ˏ(false);
            if (this.ʽ > 0.0f) {
                invalidate();
            }
        }
    }

    public void setBorderColor(@ColorInt int i) {
        setBorderColor(ColorStateList.valueOf(i));
    }

    public void setOval(boolean z) {
        this.ॱˊ = z;
        ˏ();
        ˏ(false);
        invalidate();
    }

    public void setTileModeX(TileMode tileMode) {
        if (this.ॱˋ != tileMode) {
            this.ॱˋ = tileMode;
            ˏ();
            ˏ(false);
            invalidate();
        }
    }

    public void setTileModeY(TileMode tileMode) {
        if (this.ॱᐝ != tileMode) {
            this.ॱᐝ = tileMode;
            ˏ();
            ˏ(false);
            invalidate();
        }
    }
}
